home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / dodge.swf / scripts / __Packages / Debris.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  1.6 KB  |  54 lines

  1. class Debris extends MovieClipHolder implements Steppable
  2. {
  3.    var mc;
  4.    var angle;
  5.    var speed;
  6.    var max_time;
  7.    static var BASE_DECAY = 0.9;
  8.    var timer = 0;
  9.    function Debris(x, y, color, angle, speed, time)
  10.    {
  11.       super(_root.createEmptyMovieClip("debris" + _root.getNextHighestDepth(),_root.getNextHighestDepth()),_root.effects < 2 ? null : color,false,true);
  12.       this.mc.lineStyle(2,color);
  13.       var _loc4_ = new flash.geom.Point(CustomMath.randomRange(-5,0),CustomMath.randomRange(-2,2));
  14.       this.mc.moveTo(_loc4_.x,_loc4_.y);
  15.       this.mc.lineTo(CustomMath.randomRange(0,5),CustomMath.randomRange(2,6));
  16.       this.mc.lineTo(CustomMath.randomRange(5,10),CustomMath.randomRange(-2,2));
  17.       this.mc.lineTo(CustomMath.randomRange(0,5),CustomMath.randomRange(-2,-6));
  18.       this.mc.lineTo(_loc4_.x,_loc4_.y);
  19.       this.mc._alpha = 25;
  20.       this.mc._x = x;
  21.       this.mc._y = y;
  22.       this.angle = angle;
  23.       this.speed = speed;
  24.       this.max_time = time;
  25.       this.mc._rotation = Math.random() * 360;
  26.       Stepper.add(this);
  27.    }
  28.    function step()
  29.    {
  30.       this.move();
  31.    }
  32.    function move()
  33.    {
  34.       if(this.speed > 0.1)
  35.       {
  36.          this.mc._rotation += this.speed;
  37.          var _loc3_ = CustomMath.degToRad(this.angle);
  38.          this.mc._x += this.speed * Math.cos(_loc3_);
  39.          this.mc._y += this.speed * Math.sin(_loc3_);
  40.          this.speed *= Debris.BASE_DECAY;
  41.       }
  42.       else
  43.       {
  44.          _root.debrisField.addDebris(this);
  45.          this.die();
  46.       }
  47.    }
  48.    function die()
  49.    {
  50.       this.mc.removeMovieClip();
  51.       Stepper.remove(this);
  52.    }
  53. }
  54.